package com.yeskery.nut.web.demo.controller;

import com.yeskery.nut.annotation.api.Api;
import com.yeskery.nut.annotation.api.ApiGroup;
import com.yeskery.nut.annotation.bean.Autowired;
import com.yeskery.nut.annotation.web.*;
import com.yeskery.nut.web.demo.biz.OrderBiz;
import com.yeskery.nut.web.demo.common.R;
import com.yeskery.nut.web.demo.dto.OrderDto;
import com.yeskery.nut.web.demo.dto.TakeOrderDto;
import jakarta.validation.Valid;

import java.util.List;

/**
 * 订单controller
 * @author Yeskery
 * 2023/7/28
 */
@ApiGroup("订单")
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderBiz orderBiz;

    /**
     * 获取用户订单列表
     * @return
     */
    @Api(value = "获取用户订单列表", responseClass = OrderDto.class)
    @GetMapping("/list")
    public R<List<OrderDto>> getOrderList() {
        return R.ok(orderBiz.getUserOrderList());
    }

    /**
     * 下单
     * @param dto
     * @return
     */
    @Api("下单")
    @PostMapping
    public R<?> takeOrder(@Valid @RequestBody TakeOrderDto dto) {
        return orderBiz.takeOrder(dto);
    }
}
